package hcs.ops.func;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class Login {

	
	public void hcs(WebDriver driver, String user) throws Exception {
		driver.manage().window().maximize();
		String hcs = "http://hcs-qa:2112";
		//String hcs = "http://192.168.137.5:2116/login?service=http%3A%2F%2F192.168.105.2%3A8084%2Fj_spring_cas_security_check";
		driver.get(hcs);
		System.out.println(driver.getTitle());
		
		WebElement username = driver.findElement(By.xpath("//input[@id='username']"));
		WebElement password = driver.findElement(By.xpath("//input[@id='password']"));
		WebElement button = driver.findElement(By.xpath("//input[@class='btnLogin']"));
		
		//login to hcs
		if(user.equals("admission")){
			username.sendKeys("adm8");
			password.sendKeys("123qweuser");
		}else if(user.equals("nursing")){
			username.sendKeys("10thnw");
			password.sendKeys("123qweuser");
		}else if(user.equals("billing")){
			username.sendKeys("pba1");
			password.sendKeys("123qweuser");
		}
		
		button.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

		
		try{
			driver.findElement(By.xpath("//a[@title='Logout']"));
			System.out.println("Login successful!");
		}catch(Exception e){
			System.out.println("Login failed.");
		}
		
	}
	
}
